package com.zimo.gui;

import com.zimo.Main;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Console {
    public static void main(String[] args) {
//        Memory();
        new Main().main();
        //循环接收控制台传出的指令
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print(">>> ");
            String order = scanner.nextLine();

            boolean equals = order.equals("");//如果是一个空字符就不执行
            if (!equals) {
                order = order.trim();
                String []s = order.split("\\s+");//分割命令和参数
                String [] parameter = new String[s.length-1];//保存参数
                for (int i = 1; i <= s.length-1; i++) {
                    parameter[i-1]=s[i];
                }
                //首字母大写
                s[0] = s[0].substring(0, 1).toUpperCase() + s[0].substring(1);
                //把命令对应的类传入，传入参数
                ConsoleHandleThread consoleHandleThread = new ConsoleHandleThread("com.zimo.gui.order."+s[0],parameter);
            }
        }
    }

    private static void Memory(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    FileWriter fileWriter = new FileWriter("D://tim/memory.txt");
                    fileWriter.write("当前内存\t空余内存\t已使用的内存\tJVM 可申请最大内存\n");
                    while (true){
                        Thread.sleep(500);
                        //当前虚拟机进程从操作系统申请的内存大小
                        long totalMemory =Runtime.getRuntime().totalMemory();

                        //当前虚拟机进程从操作系统申请的内存空余量
                        long freeMemory =Runtime.getRuntime().freeMemory();

                        //当前虚拟机进程从操作系统可申请的最大内存容量
                        long maxMemory =Runtime.getRuntime().maxMemory();

                        long usedMemory =totalMemory-freeMemory;//已使用的内存
                        long s = 1024*1024;//mb
                        fileWriter.write((totalMemory/s)+"\t"+(freeMemory/s)+"\t"+(usedMemory/s)+"\t"+(maxMemory/s)+"\n");
                        fileWriter.flush();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
/**
start https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe D://tim/a 32
 lists -1
 */